<template>
<div class="BookContainer" @click="gotoDetail">
<div class="img flexX">
  <img :src="imgSrc">
</div>
  <div class="content">
    <div class="name">
      {{name}}
    </div>
    <div class="price">
      ￥{{price}}
    </div>
  </div>
</div>
</template>

<script setup>
import {onMounted, ref} from "vue";
import router from "@/router";
import store from "@/store";
import {ElMessage} from "element-plus";

const props = defineProps({
  id: {
    required: false
  },name: {
    required: false
  },isbn: {
    required: false
  },press: {
    required: false
  },price: {
    required: false
  },type: {
    required: false
  }
})

const imgSrc = ref('');
const gotoDetail = () => {
  if (store.state.user !== null) {
    router.push({
      path: '/detail',
      query: {
        id : props.id
      }
    })
  } else {
    ElMessage.info('请先登录')
  }

}
onMounted(() => {
  imgSrc.value = require(`@/assets/${props.id}.jpg`)
})
</script>

<style scoped>
.BookContainer{
  width: 250px;
  min-height: 300px;
  border: 1px solid #efefef;
  margin-bottom: 15px;
  cursor: pointer;
}
.BookContainer:hover{
  border: 1px solid #eab2b2;
}
.content{
  width: 90%;
  padding-left: 10%;
}
.price{
  color: orange;
  font-size: 18px;
  font-weight: 600;
}
</style>